/*
 * XMLExportTest.java
 * JMUnit based test
 *
 * Created on 3-Dec-2009, 9:58:18 PM
 */

package ocbn.remotelab.test_package;


import java.util.Calendar;
import java.util.Vector;
import jmunit.framework.cldc10.*;
import ocbn.remotelab.events.Event;
import ocbn.remotelab.events.MassSpectrometerStateEvent;
import ocbn.remotelab.events.MassSpectrometerStateEvent.State;
import ocbn.remotelab.util.date.Date;
import ocbn.remotelab.xml.*;

/**
 * @author c9zhuron
 */
public class XMLExportTest extends TestCase {
    private long id;
    private Calendar cal;
    private String dateString;
    private Date time;
    private State stateC = State.COMPLETED;
    private State stateF = State.FAILED;
    private State stateS = State.STARTED;
    private State stateU = State.UNKNOWN;
    private String source;
    private String detail = "The detail of the project.";

    private Event event1;
    private Vector vector1 = new Vector();
    private Event event2;
    private Vector vector2 = new Vector();
    private Event event3;
    private Vector vector3 = new Vector();
    private Event event4;
    private Vector vector4 = new Vector();

    private Event mass1;
    private Event mass2;
    private Event mass3;
    private Event mass4;
    private Event mass5;
    private Vector mVector1 = new Vector();
    private Vector mVector2 = new Vector();
    private Vector mVector3 = new Vector();
    private Vector mVector4 = new Vector();
    private Vector mVector5 = new Vector();

    public XMLExportTest() {
        //The first parameter of inherited constructor is
        //the number of test cases
        super(1,"XMLExportTest");
        id = 00001;
        cal = Calendar.getInstance();
        cal.set(Calendar.YEAR, 2009);
        cal.set(Calendar.MONTH, 9);
        cal.set(Calendar.DAY_OF_MONTH, 3);
        cal.set(Calendar.HOUR, 10);
        cal.set(Calendar.AM_PM, Calendar.PM);
        cal.set(Calendar.MINUTE, 12);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        dateString = "Oct 3, 2009 10:12:00 PM";
        time = new Date(cal.getTime());
        source = "MS #1";
        event1 = new MassSpectrometerStateEvent(id,stateC,source,time);
        vector1.addElement(event1);
        event2 = new MassSpectrometerStateEvent(id,stateF,source,time);
        vector2.addElement(event2);
        event3 = new MassSpectrometerStateEvent(id,stateS,source,time);
        vector3.addElement(event3);
        event4 = new MassSpectrometerStateEvent(id,stateU,source,time);
        vector4.addElement(event4);

        mass1 = new MassSpectrometerStateEvent(id,stateC,source,time, detail);
        mass2 = new MassSpectrometerStateEvent(id,stateC,source);
        mass3 = new MassSpectrometerStateEvent(id,stateC);
        mass4 = new MassSpectrometerStateEvent(id);
        mass5 = new MassSpectrometerStateEvent();
        mVector1.addElement(mass1);
        mVector2.addElement(mass2);
        mVector3.addElement(mass3);
        mVector4.addElement(mass4);
        mVector5.addElement(mass5);

    }

    public void test(int testNumber) throws Throwable {
        switch (testNumber) {
            case 0:
                testExportXML();
                break;
            default:
                break;
        }
    }

    /**
     * Test of testExportXML method, of class XMLExport.
     */
    public void testExportXML() throws AssertionFailedException {
        System.out.println("exportXML");

        //Test for diffrent State.
        String result_1 = XMLExport.exportXML(vector1);
        String expResult_1 =
                "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
                "<data>" +
                "<event type=\"MS State\">"+
                "<id>0x1</id>" +
                "<time>"+ dateString+"</time>" +
                "<state>completed</state>" +
                "<source>MS #1</source>" +
                "</event>"+
                "</data>\n";
        String result_2 = XMLExport.exportXML(vector2);
        String expResult_2 =
                "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
                "<data>" +
                "<event type=\"MS State\">"+
                "<id>0x1</id>" +
                "<time>"+ dateString+"</time>" +
                "<state>failed</state>" +
                "<source>MS #1</source>" +
                "</event>"+
                "</data>\n";
        String result_3 = XMLExport.exportXML(vector3);
        String expResult_3 =
                "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
                "<data>" +
                "<event type=\"MS State\">"+
                "<id>0x1</id>" +
                "<time>"+ dateString+"</time>" +
                "<state>started</state>" +
                "<source>MS #1</source>" +
                "</event>"+
                "</data>\n";
        String result_4 = XMLExport.exportXML(vector4);
        String expResult_4 =
                "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
                "<data>" +
                "<event type=\"MS State\">"+
                "<id>0x1</id>" +
                "<time>"+ dateString+"</time>" +
                "<state>unknown</state>" +
                "<source>MS #1</source>" +
                "</event>"+
                "</data>\n";
        assertEquals(expResult_1, result_1);
        assertEquals(expResult_2, result_2);
        assertEquals(expResult_3, result_3);
        assertEquals(expResult_4, result_4);

        //Test for different input.
        String mResult1 = XMLExport.exportXML(mVector1);
        String mResult2 = XMLExport.exportXML(mVector2);
        String mResult3 = XMLExport.exportXML(mVector3);
        String mResult4 = XMLExport.exportXML(mVector4);
        String mResult5 = XMLExport.exportXML(mVector5);

        String mExpectResult1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
                "<data>" +
                "<event type=\"MS State\">" +
                "<id>0x1</id>" +
                "<time>"+dateString+"</time>" +
                "<state>completed</state>" +
                "<source>MS #1</source>" +
                "<details>The detail of the project.</details>" +
                "</event>" +
                "</data>\n";

        String mExpectResult2 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
                "<data>" +
                "<event type=\"MS State\">" +
                "<id>0x1</id>" +
                "<time>"+mass2.getTime()+"</time>" +
                "<state>completed</state>" +
                "<source>MS #1</source>" +
                "</event>" +
                "</data>\n";

        String mExpectResult3 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
                "<data>" +
                "<event type=\"MS State\">" +
                "<id>0x1</id>" +
                "<time>"+mass3.getTime()+"</time>" +
                "<state>completed</state>" +
                "<source>unknown mass spectrometer</source>" +
                "</event>" +
                "</data>\n";

        String mExpectResult4 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
                "<data>" +
                "<event type=\"MS State\">" +
                "<id>0x1</id>" +
                "<time>"+mass4.getTime()+"</time>" +
                "<state>unknown</state>" +
                "<source>unknown mass spectrometer</source>" +
                "</event>" +
                "</data>\n";

        String mExpectResult5 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
                "<data>" +
                "<event type=\"MS State\">" +
                "<id>0x-8000000000000000</id>" +
                "<time>"+mass5.getTime()+"</time>" +
                "<state>unknown</state>" +
                "<source>unknown mass spectrometer</source>" +
                "</event>" +
                "</data>\n";

        assertEquals(mExpectResult1, mResult1);
        assertEquals(mExpectResult2, mResult2);
        assertEquals(mExpectResult3, mResult3);
        assertEquals(mExpectResult4, mResult4);
        assertEquals(mExpectResult5, mResult5);
        //fail("The test case is a prototype.");
    }
}
